 <#include "../../common/com.html"/> <@layout>

<!-- ace styles -->
<link rel="stylesheet" href="${ctx}/static/assets/css/ace.min.css" />
<link href='${ctx}/static/assets/css/select2.css' media='all' rel='stylesheet' type='text/css' />

<script src='${ctx}/static/assets/js/select2.min.js' type='text/javascript'></script>
<script src='${ctx}/static/assets/js/select2_locale_zh-CN.js' type='text/javascript'></script>
<script type="text/javascript">
	/**
	 * 新增
	 */
	function saveModel() {
		var id = document.getElementById("id").value;
		if (Validator.Validate(document.getElementById('form1'))) {
		} else {
			return;
		}

		url = '';
		if (id == "") {
			url = '${ctx}/cpglRk/save';
		} else {
			url = '${ctx}/cpglRk/update';
		}
		$('#form1').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				alert(data);
				$("#wpid").select2("val","");
				$("#ckmc").val("");
				$("#jysj").val("");
				$("#ctyf").val("");
				$("#dtyf").val("");
				$("#wpsl").val("");
				$("#jhjg").val("");
			//		window.location.href = ' ${ctx}/cpglRk';
			}
		});

	}
</script>
<div class="page-content">
	<div class="row-fluid">
				<form class="form-horizontal" id="form1" method="post">
		<div class="span6">
				<input type="hidden" name="id" id="id">
				<input id="wpmc" name="wpmc" type="hidden" style="min-height: 24px;" />
				<div class="control-group">
					<label class="control-label">商品名称:</label>
					<div class="controls">
						<input id="wpid" name="wpid" type="text"  dataType="Require" msg="请选择商品" onchange="getmc()" style="width:200px;min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">仓库名称:</label>
					<div class="controls">
							<select name="ckmc" id="ckmc">
								<option value="" selected>无</option>
								<#list cklist as m>
								<option value="${(m.id)!}" >${(m.ckmc)!}</option>
								</#list>
							</select>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label">建议售价:</label>
					<div class="controls">
						<input id="jysj" name="jysj" type="text" class="  easyui-numberbox " maxlength="10"   precision="1"    style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">长途运费:</label>
					<div class="controls">
						<input id="ctyf" name="ctyf" type="text" class="  easyui-numberbox "  maxlength="10"  precision="1"  style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">短途运费:</label>
					<div class="controls">
						<input id="dtyf" name="dtyf" type="text"  class="  easyui-numberbox " maxlength="10"   precision="1"  style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">商品数量:</label>
					<div class="controls">
						<input id="wpsl" name="wpsl" type="text" dataType="Require" maxlength="10"  msg="请输入商品数量" class="  easyui-numberbox "  style="min-height: 24px;" />
					</div>
				</div>
		</div>
			<div class="span6">
				<div class="control-group">
					<label class="control-label">进货厂家:</label>
					<div class="controls">
						<input id="jhcjid" name="jhcjid" type="text"  onchange="getcjxx()" style="width:200px;min-height: 24px;" />
					
						<input id="jhcj" name="jhcj" type="hidden" style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">厂家电话:</label>
					<div class="controls">
						<input id="cjdh" name="cjdh" maxlength="15"  type="text" style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">厂家微信:</label>
					<div class="controls">
						<input id="cjwx" name="cjwx"  maxlength="15" type="text" style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">厂家qq:</label>
					<div class="controls">
						<input id="cjqq" name="cjqq" type="text"  maxlength="15" style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">总价:</label>
					<div class="controls">
						<input id="jhjg" name="jhjg" class="  easyui-numberbox "  dataType="Require" msg="请输入价格"  precision="1"  type="text" style="min-height: 24px;" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">入库方式:</label>
					<div class="controls">
							<select name="yxbz" id="yxbz">
								<option value="1"  selected="selected"> 进货入库</option>
								<option value="2" >报溢入库</option>
							</select>
					</div>
				</div>

		</div>
		
				<div class="span12 center">
				<a  class="btn btn-info btn-small" onclick="saveModel()">确定
				</a> &nbsp; &nbsp;&nbsp;&nbsp; 
								<a href="#"  class="btn btn-danger btn-small bigger-110"  onclick="window.location.href=' ${ctx}/cpglCk'"  >取消 </a>
				
		</div>
</form>
		
	</div>
</div>

</body>

<script>
	/**
	 * 修改页面使用
	 */

	<#list newlist as m>
	document.getElementById("id").value = '${(m.id)!}';
	document.getElementById("wpid").value = '${(m.wpid)!}';
	document.getElementById("wpmc").value = '${(m.wpmc)!}';
	document.getElementById("jysj").value = '${(m.jysj)!}';
	document.getElementById("ctyf").value = '${(m.ctyf)!}';
	document.getElementById("dtyf").value = '${(m.dtyf)!}';
	document.getElementById("wpsl").value = '${(m.wpsl)!}';
	document.getElementById("jhcj").value = '${(m.jhcj)!}';
	document.getElementById("cjdh").value = '${(m.cjdh)!}';
	document.getElementById("cjwx").value = '${(m.cjwx)!}';
	document.getElementById("cjqq").value = '${(m.cjqq)!}';
	document.getElementById("jhjg").value = '${(m.jhjg)!}';
	document.getElementById("ckmc").value = '${(m.ckmc)!}';
	document.getElementById("yxbz").value = '${(m.yxbz)!}';

	</#list>
	
	$('#wpid').select2({
	    placeholder: "输入名称,编号或者拼音首字母",
	    minimumInputLength: 1,
	    ajax: {
	        url: "/cgglWp/getWpxx",
	        dataType: 'json',
	        data: function (term, page) {
	            return {
	                term: term  ,
	                page_limit: 20,
	                page: 0,
	                apikey: "getwpxx"
	            };
	        },
	        results: function (data, page) {
	            return { results: data};
	        }

	    }
	});
	$('#jhcjid').select2({
	    placeholder: "请输入厂家名称或者编号",
	    minimumInputLength: 1,
	    ajax: {
	        url: "/cgglWp/getCj",
	        dataType: 'json',
	        data: function (term, page) {
	            return {
	                term: term  ,
	                page_limit: 20,
	                page: 0,
	                apikey: "getcjxx"
	            };
	        },
	        results: function (data, page) {
	            return { results: data};
	        }

	    }
	});
	
	  // select2 初始化
    <#list newlist as m>
    $("#wpid").select2("data", {id: "${(m.wpid)!}", text: "${(m.wpmc)!}"});
    $("#jhcjid").select2("data", {id: "${(m.jhcjid)!}", text: "${(m.jhcj)!}"});
    </#list>
	// 商品取值
	function getmc(){
	    var data = $("#wpid").select2("data");
	    var objs=JSONstringify(data);
	    var arr = eval('(' + objs + ')');
	    document.getElementById("wpmc").value=(arr['text']==undefined ) ? "" : arr['text'];
	    document.getElementById("jysj").value=(arr['text']==undefined ) ? "" : arr['ckdj'];

	}
	function getcjxx(){
	    var data = $("#jhcjid").select2("data");
	    var objs=JSONstringify(data);
	    var arr = eval('(' + objs + ')');
	    document.getElementById("jhcj").value=(arr['text']==undefined ) ? "" : arr['text'];
	    document.getElementById("cjdh").value=(arr['lxdh']==undefined ) ? "" : arr['lxdh'];
	    document.getElementById("cjwx").value=(arr['wx']==undefined ) ? "" : arr['wx'];
	    document.getElementById("cjqq").value=(arr['qq']==undefined ) ? "" : arr['qq'];

	}
	//转json
	function JSONstringify(Json){
	    if($.browser.msie){
	        if($.browser.version=="7.0"||$.browser.version=="6.0"){
	            var  result=jQuery.parseJSON(Json);
	        }else{
	            var result=JSON.stringify(Json);
	        }
	    }else{
	        var result=JSON.stringify(Json);
	    }
	    return result;
	}
</script>
</@layout>
